package com.dream.keigezhushou.Activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.bean.TicketInfo;
import com.dream.keigezhushou.R;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;

public class GetTicketCentreActivity extends BaseActivity implements View.OnClickListener {

    private PullToRefreshListView mPull;
    private ArrayList<TicketInfo> list = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_ticket_centre);

        mPull = (PullToRefreshListView) findViewById(R.id.list_centre);



        ListView mlist =  mPull.getRefreshableView();

        ImageView ivback = (ImageView) findViewById(R.id.back);
        ivback.setOnClickListener(this);
          initData();
        mlist.setAdapter(new MyAdapter(list));
    }

    private void initData() {
        for (int i=0 ;i<10;i++){
            TicketInfo info = new TicketInfo();
            info.setValidity("20017.1.20-2017.3.28");
            info.setName_ktv("乐唱好声音KTV");
            info.setTicketprice("20");
            info.setAvailableprice("1000");
            list.add(info);

        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
            break;


        }

    }

    private class MyAdapter extends BaseAdapter {
        private ArrayList<TicketInfo> list;

        public MyAdapter(ArrayList<TicketInfo> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public TicketInfo getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if(convertView==null) {
                convertView = UiUtils.inflateView(R.layout.item_ticket);
                holder = new ViewHolder();
                holder.ticketprice = (TextView) convertView.findViewById(R.id.price_usable);

                holder.availableprice = (TextView) convertView.findViewById(R.id.des);

                holder.name_ktv = (TextView) convertView.findViewById(R.id.name);

                holder.validity = (TextView) convertView.findViewById(R.id.validity);

                holder.tv = (TextView) convertView.findViewById(R.id.tv);

                convertView.setTag(holder);
            }else{
                holder= (ViewHolder) convertView.getTag();
            }

            TicketInfo info = getItem(position);
            holder.ticketprice.setText(info.getTicketprice());
            holder.availableprice.setText("满"+info.getAvailableprice()+"元可用");
            holder.name_ktv.setText(info.getName_ktv());
            holder.validity.setText(info.getValidity());

            holder.tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    UiUtils.toast("领取成功");

                    //
                }
            });



            return convertView;
        }
    }
    static  class  ViewHolder{
        private TextView ticketprice;
        private TextView  availableprice;
        private TextView  name_ktv;
        private TextView  validity;
        private  TextView tv;
    }
}
